<?php
namespace app\admin\controller;

use app\common\cache\common\IAreaCache;
use app\common\cache\user\IUserCache;
use app\common\cache\user\IUserLevelCache;
use app\common\controller\AdminBaseController;
use app\common\enum\UserPoolBidType;
use app\common\enum\PoolBidStatus;
use app\common\enum\UserStatus;
use app\common\ext\IDb;
use app\common\ext\IRequest;

class AgentAdminTender extends AdminBaseController{
    /**
     * @功能：投标记录列表
     * @开发者：cxl
     * @return string
     */
    public function agent_admin_tender_list(){
        //接收参数
        $agent_admin_tender_id = IRequest::get("agent_admin_tender_id");
        $agent_id = IRequest::get("agent_id");
        $cooperate_id = IRequest::get("cooperate_id");
        $user_pool_bid_id = IRequest::get("user_pool_bid_id");
        $tender_status = IRequest::get("tender_status");

        //判断客户池类型
        $agent_admin_tender_where = null;
        if(!empty($agent_admin_tender_id))$agent_admin_tender_where['aa.agent_admin_tender_id'] = $agent_admin_tender_id;
        if(!empty($user_pool_bid_id))$agent_admin_tender_where['aa.user_pool_bid_id'] = $user_pool_bid_id;
        if(!empty($agent_id))$agent_admin_tender_where['aa.agent_id'] = $agent_id;
        if(!empty($cooperate_id))$agent_admin_tender_where['up.cooperate_id'] = $cooperate_id;
        if(!empty($tender_status))$agent_admin_tender_where['aa.tender_status'] = $tender_status;
        $agent_admin_tender_list = IDb::getInstance("agent_admin_tender as aa")
            ->setDbFiled('aa.*,up.money,up.cooperate_id,up.period,up.purpose,co.cooperate_name,coa.nick as cooperate_admin_name,aga.real as agent_admin_real')
            ->setDbJoin('user_pool_bid as up','up.user_pool_bid_id = aa.user_pool_bid_id')
            ->setDbJoin('agent_admin as aga','aga.agent_admin_id = up.agent_admin_id','left')
            ->setDbJoin('cooperate as co','co.cooperate_id = up.cooperate_id','left')
            ->setDbJoin('cooperate_admin as coa','coa.cooperate_admin_id = up.cooperate_admin_id','left')
            ->setDbWhere($agent_admin_tender_where)
            ->setDbOrder('aa.agent_admin_tender_id desc')
            ->pag();
        echo IDb::getDbLastSql();

        if ($agent_admin_tender_list === false){
            error('获取投标记录失败');
        }

        //页面赋值
        $this->assign("agent_admin_tender_id",$agent_admin_tender_id);
        $this->assign("tender_status",$tender_status);
        $this->assign("agent_id",$agent_id);
        $this->assign("user_pool_bid_id",$user_pool_bid_id);
        $this->assign("cooperate_id",$cooperate_id);
        $this->assign("agent_admin_tender_list",$agent_admin_tender_list);

        //渲染模板输出
        return view();
    }
    /**
     * @功能：投标记录详情
     * @开发者：cxl
     * @return string
     */
    public function agent_admin_tender_info(){
        //接收参数
        $agent_admin_tender_id = IRequest::get('agent_admin_tender_id',IRequest::NOT_EMPTY,"投标编号不能为空！");

        $agent_admin_tender_where['aa.agent_admin_tender_id'] = $agent_admin_tender_id;
        $agent_admin_tender_info = IDb::getInstance("agent_admin_tender as aa")
            ->setDbFiled('aa.*,up.money,up.create_time,up.open_time,up.stop_time,up.bid_start,up.user_note,up.cooperate_id,up.period,up.purpose,aga.real,aga.phone,aga.agent_admin_id,co.cooperate_id,co.cooperate_name,coa.phone as cooperate_admin_phone,coa.nick as cooperate_admin_name,coa.cooperate_admin_id')
            ->setDbJoin('user_pool_bid as up','up.user_pool_bid_id = aa.user_pool_bid_id')
            ->setDbJoin('agent_admin as aga','aga.agent_admin_id = up.agent_admin_id','left')
            ->setDbJoin('cooperate as co','co.cooperate_id = up.cooperate_id','left')
            ->setDbJoin('cooperate_admin as coa','coa.cooperate_admin_id = up.cooperate_admin_id','left')
            ->setDbWhere($agent_admin_tender_where)
            ->setDbOrder('aa.agent_admin_tender_id desc')
            ->row();

        if ($agent_admin_tender_info === false){
            error('获取投标记录失败');
        }

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("agent_admin_tender_info",$agent_admin_tender_info);

        //渲染模板输出
        return view();

    }
}